/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.velocityme.entity;

import java.util.ArrayList;
import java.util.Collection;
import javax.persistence.Entity;
import javax.persistence.ManyToMany;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;

/**
 *
 * @author rcrida
 */
@Entity
@Table(name="xgroup")
@NamedQuery(name="findAllGroups",
            query="SELECT o FROM Group o WHERE o.deleted = FALSE")
public class Group extends Node {
    private static final long serialVersionUID = 1L;

    @ManyToMany
    private Collection<User> users = new ArrayList<User>();

    @OneToMany(mappedBy = "group")
    private Collection<GroupAccess> groupAccesses;

    public Collection<User> getUsers() {
        return users;
    }

    public Collection<GroupAccess> getGroupAccessesGroup() {
        return groupAccesses;
    }

    public void addUser(User user) {
        if (!users.contains(user)) {
            users.add(user);
        }
    }

    public void clearUsers() {
        users.clear();
    }

}
